# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
use_frameworks!
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release,
}

source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/aliyun/aliyun-specs.git'

# 飞燕
def livingLink_v9
  pod 'IMSApiClient', '1.6.9'
  pod 'IMSAuthentication', '1.4.3'
  pod 'IMSIotSmart', '1.2.6'
  pod 'AlicloudSecurityGuardSDK', '5.5.51'
  pod 'AlicloudSGSecurityBody', '5.5.60'
  pod 'AlicloudSGMain', '5.5.51'
  pod 'AlicloudALBBOpenAccount', '3.4.0.54'
  pod 'IMSThingCapability', '1.8.10'
  pod 'IMSMobileChannel', '1.6.12'
  pod 'IMSBoneKit', '1.3.11.11'
  pod 'AKReactNative', '0.59.9.2'
  pod 'MJRefresh', '3.1.15'
  pod 'ZipArchive', '1.4.0'
  pod 'IMSReactNativeExtension', '1.0.2'
  pod 'IMSDeviceCenter', '1.13.3'
  pod 'CocoaAsyncSocket', '7.4.2'
  pod 'Reachability', '3.2'
  pod 'IMSBreezeSDK', '1.7.7'
  pod 'IMSOtaBusinessSdk', '1.6.3'
  pod 'IMSDeviceGateway', '1.6.8'
end

def collection
  livingLink_v9
end

def flutter_root
  generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
  unless File.exist?(generated_xcode_build_settings_path)
    raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
  end

  File.foreach(generated_xcode_build_settings_path) do |line|
    matches = line.match(/FLUTTER_ROOT\=(.*)/)
    return matches[1].strip if matches
  end
  raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
  use_frameworks!
  use_modular_headers!
  collection

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

post_install do |installer|
   installer.pods_project.build_configuration_list.build_configurations.each do |configuration|
        configuration.build_settings['CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES'] = 'YES'
    end

    installer.aggregate_targets.each do |target|

        copy_pods_resources_path = "Pods/Target Support Files/#{target.name}/#{target.name}-resources.sh"
        string_to_replace = '--compile "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"'
        assets_compile_with_app_icon_arguments = '--compile "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" --app-icon "${ASSETCATALOG_COMPILER_APPICON_NAME}" --output-partial-info-plist "${BUILD_DIR}/assetcatalog_generated_info.plist"'
        text = File.read(copy_pods_resources_path)
        new_contents = text.gsub(string_to_replace, assets_compile_with_app_icon_arguments)
        File.open(copy_pods_resources_path, "w") {|file| file.puts new_contents }
    end
    installer.pods_project.targets.each do |target|
        flutter_additional_ios_build_settings(target)
        if target.name == 'Pods-MXCHIP'
            target.build_configurations.each do |config|
                config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
                config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'MXCHIP_1'
#                puts "===================>target build configure #{config.build_settings}"
            end
        end

        target.build_configurations.each do |config|
#             config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'No'
            config.build_settings['ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES'] = 'YES'
            config.build_settings['CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES'] = 'YES'
        end
    end
end
